package com.atqh.logistics.controller.Manager;

import com.atqh.logistics.Aop.LogAnnotation;
import com.atqh.logistics.domin.Driver;
import com.atqh.logistics.domin.Notice;
import com.atqh.logistics.mapper.NoticeMapper;
import com.atqh.logistics.service.NoticeService;
import com.atqh.logistics.utils.ErrorCode;
import com.atqh.logistics.utils.Result;
import com.atqh.logistics.utils.Vo.params.DriverParam;
import com.atqh.logistics.utils.Vo.params.NoticeParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @作者：大叔azhe
 * @api：详细描述
 * @创建时间：11:02 2023/4/12
 */
@Api(tags = "公告功能模块")
@RestController
@CrossOrigin
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;
    @Autowired
    private NoticeMapper noticeMapper;

    @ApiOperation("管理员发布公告")
    @RequestMapping("/public")
    @LogAnnotation(module = "管理员模块", operator = "发布公告")
    public Result publicNotice(@RequestBody NoticeParam noticeParam) {
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeParam, notice);
        notice.setIsDeleted(0);
        int insert = noticeMapper.insert(notice);
        if (insert != 1)
            return Result.Fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMsg());
        return Result.success(notice);

    }

    @ApiOperation("管理员删除公告")
    @RequestMapping("/delete/{nid}")
    @LogAnnotation(module = "管理员模块", operator = "删除公告")
    public Result deleteNotice(@PathVariable("nid") int noticeId) {
        int delete = noticeMapper.deleteById(noticeId);
        if (delete != 1)
            return Result.Fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMsg());
        return Result.success(delete);

    }

    @ApiOperation("司机查看所有公告")
    @RequestMapping("/View")
    @LogAnnotation(module = "司机模块", operator = "查看公告")
    public Result ViewNotice() {

        List<Notice> notices = noticeMapper.selectList(null);
        return Result.success(notices);

    }
}
